<template>
    <div class="cmt-Warp">
        <h3>发表评论</h3>
        <hr>
        <textarea name="" id="" placeholder="请输入要BB的内容（最多吐槽120字）" maxlength="120"></textarea>
        <mt-button type="primary" size="large">发表评论</mt-button>
        <div class="cmt-list">
            <div class="cmt-item" v-for="(item, i) in comments" :key="i">
                <div class="cmt-title">
                    第{{ i +1}}楼&nbsp;&nbsp;用户：{{ item.user_name }}&nbsp;&nbsp;发表时间：{{ item.add_time | dateFormat() }}
                </div>
                <div class="cmt-body">
                    {{ item.content === 'undefined'? '啥也没写' : item.content}}
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain="" @click="getMore()">加载更多</mt-button>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';
    export default {
        data(){
            return{
                pageIndex: 1,
                comments: []
            }
        },
        created(){
            this.getComments()
        },
        methods:{
            getComments(){
                this.$http.get('api/getcomments/'+this.id+'?pageindex='+this.pageIndex)
                    .then(result =>{
                        var res = result.body;
                        if(res.status === 0){
                           if(res.message == ''){
                               console.log("没有更多评论了！")
                           }else{
                               this.comments = this.comments.concat(res.message);
                           }
                            // console.log(res.message)
                        }else{
                            Toast("获取评论列表失败！")
                        }
                    });
            },
            getMore(){
                this.pageIndex ++;
                this.getComments();
            }
        },
        props: ["id"]
    }
</script>

<style scoped lang="scss">
    button{
        font-size: 14px;
    }
    .cmt-Warp{
        padding: 0 15px;
        h3{
            font-size: 18px;
        }
        textarea{
            font-size: 14px;
        }
        .cmt-list{
            margin: 5px 0;
            .cmt-item{
                font-size: 13px;
                .cmt-title{
                    line-height: 30px;
                    background-color: #f7f7f7;
                }
                .cmt-body{
                    line-height: 35px;
                    text-indent: 2em;
                    min-height: 35px;
                }
            }
        }
    }
</style>